@echo off
set date=%date:~4%
if %date:~0,1%==2 (
  rem echo win2000
  goto OK
)
rem echo winXP
set date=%date:~4,-3% 
: OK

rem 2012-09-15
set ORACLE_HOME1=%ORACLE_HOME%
set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
set path1=%PATH%
IF NOT "%2"=="NULL" SET ORACLE_HOME=%2
set path2=%ORACLE_HOME%
IF exist %path2%\oci.dll GOTO Okpath
IF exist %path2%\bin\oci.dll (
  set path2=%path2%\bin
  GOTO Okpath
)
:Okpath
set PATH=%path2%\;%PATH1%
set expproc=imp.exe
IF exist %path2%\imp.exe (
  set expproc=%path2%\imp.exe
  GOTO Okexp
)
IF exist %path2%\imp80.exe (
  set expproc=%path2%\imp80.exe
  GOTO Okexp
)
:Okexp
set TNS_ADMIN1=%TNS_ADMIN%
set TNS_ADMIN=%ORACLE_HOME%
IF NOT "%ORACLE_HOME%"=="%path2%" SET TNS_ADMIN=%ORACLE_HOME%\network\ADMIN


set username=erpsys
rem set expproc=d:\oracle\ora90\bin\imp
set server=erpsys@erp
set arcdir=e:\databak
set rardir=c:\progra~1\winrar\
set parfile=NULL
set istemp=
set impfilename=

IF NOT "%1"=="" SET username=%1
rem IF NOT "%2"=="" SET expproc=%2
IF NOT "%3"=="" SET server=%3
IF NOT "%4"=="" SET arcdir=%4
rem IF NOT "%5"=="" 
SET rardir=%5
IF NOT "%6"=="NULL" SET date=%6
rem IF NOT "%7"=="NULL" 
SET parfile=%7
SET istemp=%8
SET impfilename=%9

rem echo %parfile% %expproc% %username% %server% %date%

rem D:\oracle\ora81\bin\SQLPLUSW.EXE dwadmin/dwadmin@iterp @D:\bakdata\erpsys\delerp.sql

set filename=%username%_%date%
if not "%parfile%"=="NULL" (
    set filename=%username%_%date%_%parfile%
	goto par
)
IF exist .\par\IMP_default.par set parfile=IMP_default

:par

if "%istemp%"=="temp" set parfile=IMP_temp

IF not exist %username% md %username%
cd %username%
IF not exist log md log
IF not exist %arcdir%\%username% md %arcdir%\%username%

:start
start /MIN /WAIT %expproc% %username%/%server% parfile=..\par\%parfile%.par file=%impfilename% log=.\log\IMP_%filename%.log

:zip
if not "%rardir%"=="NULL" (
rem   IF exist %filename%.dmp start /MIN /WAIT %rardir%winrar a -idp -ao %arcdir%\%username%\%filename%.rar %filename%.dmp 
  IF exist .\log\IMP_%filename%.log  start /MIN /WAIT %rardir%winrar m -idp -ao %arcdir%\%username%\%username%_log.rar .\log\IMP_%filename%.log 
  IF exist .\log\IMP_%filename%_sql.log  start /MIN /WAIT %rardir%winrar m -idp -ao %arcdir%\%username%\%username%_log.rar .\log\IMP_%filename%_sql.log 
)
cd ..

if %ERRORLEVEL%==0 (
   if exist deloldfile.exe (
rem       deloldfile %date% %7 %8
       goto end
   )
   echo not deloldfile.exe
   goto end
)
echo %ERRORLEVEL%

rem goto end

:end
set username=
set expproc=
set server=
set arcdir=
set rardir=
set parfile=
set date=
set filename=
set istemp=

set PATH=%PATH1%
set ORACLE_HOME=%ORACLE_HOME1%
set PATH1=
set path2=
set ORACLE_HOME1=
set TNS_ADMIN=%TNS_ADMIN1%
set TNS_ADMIN1=


@echo on
